package com.software.jump.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.software.jump.R;
import com.software.jump.entity.Student;

import java.io.Serializable;

public class StudentDetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_student_detail);
        EditText edt_student_name = findViewById(R.id.edt_student_name);
        //获取Intent
        Intent intent = getIntent();
        //第一种接收
        //        String name = intent.getStringExtra("name");
        //第二种接收
//        Bundle bundle = intent.getExtras();
//        String name = bundle.getString("name");
        //第三种接收
        Student student = (Student) intent.getSerializableExtra("student");
        //设置数据
        edt_student_name.setText(student.getName());

        Button btn_back = findViewById(R.id.btn_back);
        btn_back.setOnClickListener(v -> {
            //返回数据
            Intent back = new Intent();
            back.putExtra("newStudentName", edt_student_name.getText().toString());
            setResult(201, back);
            finish();
        });
        //打开另一个app的Activity
        Button btn_other = findViewById(R.id.btn_other);
        btn_other.setOnClickListener(v -> {
            Intent other = new Intent();
            ComponentName componentName = new ComponentName(
                    "com.software.thread",
                    "com.software.thread.MainActivity"
            );
            other.setComponent(componentName);
            startActivity(other);
        });

    }
}